﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InControl
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //((INV_MDIParent)this.MdiParent).appDriver.pid = ((INV_MDIParent)this.MdiParent).appDriver.Authenticate(textBox1.Text, textBox2.Text);/*db.Authenticate(textBox1.Text, textBox2.Text);*/
            //if (((INV_MDIParent)this.MdiParent).appDriver.pid != -1)
            
            //    ((INV_MDIParent)this.MdiParent).OpenForm(typeof(INV_home_form));
            //}
            try
            {
                if (((INV_MDIParent)this.MdiParent).appDriver.Authenticate(textBox1.Text, textBox2.Text))
                {
                    ((INV_MDIParent)this.MdiParent).OpenForm(typeof(INV_home_form));
                }
                else
                {
                    Error_form ef = new Error_form();
                    ef.richTextBox1.Text = "not authorized";
                    ef.ShowDialog(this);
                }
            }
            catch (Exception ex)
            {
                ((INV_MDIParent)this.MdiParent).appDriver.pid = -1;
                ((INV_MDIParent)this.MdiParent).appDriver.CloseConnection();
                Error_form ef = new Error_form();
                ef.richTextBox1.Text = ex.Message;
                ef.ShowDialog(this);
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
        }

        private void TextBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                button1_Click(sender, e);
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        }

    }
}
